package com.ljh.mybatisplusdemo.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.ljh.mybatisplusdemo.model.UserInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author: Themberfue
 * @date: 2025/3/18 20:26
 * @description:
 */
@Mapper
public interface UserInfoMapper extends BaseMapper<UserInfo> { // ? 继承 BaseMapper 后可以使用 mybatis-plus 提供的各种方法
    @Select("select * from user_info where id = #{id}")
    UserInfo selectById1(Integer id);

    UserInfo selectById2(Integer id);

    @Select("select id, username, password, age from user_info ${ew.customSqlSegment}")
    List<UserInfo> selectByCondition(@Param(Constants.WRAPPER) Wrapper<UserInfo> queryWrapper);

    List<UserInfo> selectByCondition2(@Param(Constants.WRAPPER) Wrapper<UserInfo> queryWrapper);

    @Select("update user_info set age = age + #{addAge} ${ew.customSqlSegment}")
    Integer updateById(Integer addAge, @Param(Constants.WRAPPER) Wrapper<UserInfo> queryWrapper);

    Integer updateById2(Integer subAge, @Param(Constants.WRAPPER) Wrapper<UserInfo> queryWrapper);
}
